<?php

/**
 * Smarty {muffin_GetPages} function plugin
 *
 * Type:     function
 * Name:     muffin_getpages
 * Purpose:  Easy smarty function linked to the muffin function: getPages()
 * 
 * @author Kozie <flamefingers at gmail dot com>
 * @param array
 * @param Smarty
 */

function smarty_function_muffin_getPages( $params, &$smarty )
{
	
	// Muffin declareren
	$m	= Muffin::instance();
	
	// Check of de range parameter gezet is
	if ( !empty($params['range']) && is_numeric($params['range']) ) {
		
		$pages = $m->getPages( $params['range'] );
		$range = $params['range'];
		
    } else {
    	
    	$pages = $m->getPages( $m->_cfg['pagerange'] );
    	$range = $m->_cfg['pagerange'];
    	
    }
    
	
    // Knopje voor vorige pagina
    if ( $m->page > 1 )
			$return .= '<a href="?p=' . $m->prevpage . '" class="prevpage">&lsaquo</a> ';
			
			
	// Check of de eerste pagina onzichtbaar is
	// Anders weergeven
	if ( ($m->page - $range) > 1 )
		$return .= '<a href="?p=1" class="firstpage">1</a>.. ';
		
    
    // Alle pagina nummers weergeven
    foreach( $pages as $p ) {

    	if ( $p == $m->page ) {
    		
    		$return .= '<span>[' . $p . ']</span> ';
    		
    	} else {
    		
    		$return .= '<a href="?p=' . $p . '">' . $p . '</a> ';
    		
    	}
    	
		
	}
	
	
	// Check of de laatste pagina onzichtbaar is
	// Anders weergeven
	if ( ($m->page + $range) < $m->pcount )
		$return .= '..<a href="?p=' . $m->pcount . '" class="lastpage">' . $m->pcount . '</a> ';
		
	
	// Knopje voor volgende pagina
	if ( $m->page < $m->pcount )
			$return .= '<a href="?p=' . $m->nextpage . '" class="nextpage">&rsaquo</a>';
	
	
	return $return;
	
}

?>